<?php
    include("includes/connect_db.php");
    $id_outbox = $_POST['id_outbox'];
    $temp = $_POST['temp'];
?>

<div>                      
    <ul class="breadcrumb-modal" style="background-color: #0088cc; color: #FFF; text-shadow: none; font-family: 'SEGOE UI'">
        <li id="delete-conv" style="cursor: pointer;" title="Hapus Pesan" data-placement="bottom" data-animation="true">
            <i class="icon-trash icon-white"></i> 
            Hapus
        </li>
        <li id="reply" style="cursor: pointer;" title="Balas Pesan" data-placement="bottom" data-animation="true">
            <i class="icon-share-alt flip icon-white"></i> 
            Balas
        </li>
        
        <?php 
            if ($temp == 0) {
            } else if ($temp == 1) {
        ?>
                <li class="add-contact" style="cursor: pointer;" title="Tambahkan Ke Kontak" data-placement="bottom" data-animation="true">
                    <i class="icon-plus icon-white"></i>
                    Tambah Kontak
                </li>
        <?php
            }
        ?>
        
        <li class="pull-right" id="single-msg" style="cursor: pointer;" title="Kembali Ke Pesan" data-placement="bottom" data-animation="true">
            <i class="icon-arrow-left icon-white"></i>
            Kembali
        </li>
    </ul>
</div>
<div style="min-height: 100px; max-height: 350px; overflow: auto; margin: 1px 10px; padding: 5px; background-color: #F5F5F5; color: #7B7B7B; font-family:'SEGOE UI'">
    <?php 
        $sql_cari_nomor = "select DestinationNumber from sentitems where ID = '$id_outbox'";
        $query_cari_nomor = mysql_query($sql_cari_nomor);
        $cari_nomor = mysql_fetch_array($query_cari_nomor);

        $sql_update =  "UPDATE inbox SET Status = 2 WHERE SenderNumber = $cari_nomor[DestinationNumber]";
        $query_update = mysql_query($sql_update);

        $sql_tampil_pesan = "SELECT * 
                            FROM    (SELECT 
                                        TextDecoded AS isi, 
                                        SenderNumber AS nomer, 
                                        UpdatedInDB as waktudb,
                                        CONCAT( DAY(UpdatedInDB),' ',
                                                MONTHNAME(UpdatedInDB),' ',
                                                YEAR(UpdatedInDB),', ',
                                                DATE_FORMAT(UpdatedInDB,'%h:%i %p'))
                                                AS waktu,
                                        CONCAT( DATE_FORMAT(UpdatedInDB,'%h:%i %p'))
                                                AS jam,
                                        CONCAT( DAY(UpdatedInDB),' ',
                                                MONTHNAME(UpdatedInDB),' ',
                                                YEAR(UpdatedInDB))
                                                AS tanggal, 
                                        'inbox' AS asal 
                                    FROM inbox
                                    WHERE SenderNumber = '$cari_nomor[DestinationNumber]') 
                                    AS inbox 
                            UNION   (SELECT 
                                        TextDecoded AS isi, 
                                        DestinationNumber AS nomer, 
                                        UpdatedInDB as waktudb,
                                        CONCAT( DAY(UpdatedInDB),' ',
                                                MONTHNAME(UpdatedInDB),' ',
                                                YEAR(UpdatedInDB),', ',
                                                DATE_FORMAT(UpdatedInDB,'%h:%i %p'))
                                                AS waktu,
                                        CONCAT( DATE_FORMAT(UpdatedInDB,'%h:%i %p'))
                                                AS jam,
                                        CONCAT( DAY(UpdatedInDB),' ',
                                                MONTHNAME(UpdatedInDB),' ',
                                                YEAR(UpdatedInDB))
                                                AS tanggal, 
                                        'outbox' AS asal 
                                    FROM sentitems
                                    WHERE DestinationNumber = '$cari_nomor[DestinationNumber]')
                            ORDER BY waktudb";

        $query_tampil_pesan = mysql_query($sql_tampil_pesan);
        $temp_tanggal = '';
        while($tampil_pesan = mysql_fetch_array($query_tampil_pesan)){
            if ($temp_tanggal == '') {
                echo "<p align='center' style='font-size: 10px;'>$tampil_pesan[tanggal]</p>";    
            } elseif ($temp_tanggal != $tampil_pesan['tanggal']) {
                echo "<p align='center' style='font-size: 10px;'>$tampil_pesan[tanggal]</p>";
            }
            
            if ($tampil_pesan[asal] == 'inbox'){
                echo "  <div style='max-width: 400px; color: #0088cc; padding: 0 0 10px 0; border-bottom: 1px solid #FFF;'>";
                echo "      $tampil_pesan[isi]";
                echo "      <p style='font-size: 8px; padding: 0; margin: 0; color: #7B7B7B;'>$tampil_pesan[jam]</p>";
                echo "  </div>";
            } elseif ($tampil_pesan[asal] == 'outbox') {
                echo "<div style='text-align: right; margin-left: auto; color: #0088cc; max-width: 400px; padding: 0 0 10px 0; border-bottom: 1px solid #FFF;'>";
                echo "      $tampil_pesan[isi]";
                echo "      <p style='font-size: 8px; padding: 0; margin: 0; color: #7B7B7B;'>$tampil_pesan[jam]</p>";
                echo "  </div>";
            }
            $temp_tanggal = $tampil_pesan['tanggal'];
        }
    ?>
</div>
<div style="min-height: 60px; margin: 1px 10px; padding: 5px 5px 0 5px; background-color: #F5F5F5; color: #7B7B7B; font-family:'SEGOE UI'">
    <div class="input-prepend">
        <textarea id="reply-msg" placeholder="Type to Reply ..." style="font-family:'SEGOE UI'; overflow: hidden; word-wrap: break-word; resize: none; height: 50px; width: 425px;"></textarea>
        <span id="send-msg" class="add-on" style="cursor: pointer; height: 50px; width: 50px; background-color: #0088cc;">
            <table height="100%" width="100%"><tr><td align="center" style="vertical-align: middle; font-family:'SEGOE UI'; color: #FFF;">
                Send
            </td></tr></table>
        </span>
    </div>
</div>

<script type="text/javascript">
    $(document).ready(function(){
        $('#delete-msg').tooltip();
        $('#reply').tooltip();
        $('#forward').tooltip();
        $('.add-contact').tooltip();
        $('#single-msg').tooltip();
    });
    
</script>